public final class MyString {
    private final char[] value;

    public MyString(char[] value) {
        this.value = value;
    }

    public MyString(String s){
        this.value = new char[s.length()];
        for (int i = 0; i < s.length(); i++) {
            value[i] = s.charAt(i);
        }
    }

    public char charAt(int i){
        if(i >= 0 && i < value.length)
            return this.value[i];
        throw new StringIndexOutOfBoundsException(i);
    }

    public String toString(){
        return new String(this.value);
    }
    public MyString trim(){
        int k = 0;
        for(char ch : value){
            if(ch != ' ')
                k++;
        }
        char[] ans = new char[k];
        k = 0;
        for (char ch: value) {
            if(ch != ' ')
                ans[k++] = ch;
        }
        return new MyString(ans);
    }

    public int compareToIgnoreCase(MyString s){
        for(int i=0; i<this.value.length && i<s.value.length; i++){
            char s1 = this.value[i];
            char s2 = s.value[i];
            if(s1 <= 'Z' && s1 >= 'A')
                s1 -= 'A'-'a';
            if(s2 <= 'Z' && s2 >= 'A')
                s2 -= 'A'-'a';
            if(s1 != s2) return s1 - s2;
        }
        return this.value.length - s.value.length;
    }

    public static void main(String[] args) {
        MyString myString = new MyString(" a b c ");
        System.out.println(myString);
        MyString ret = myString.trim();
        System.out.println(ret);

        MyString s1 = new MyString("addc");
        MyString s2 = new MyString("ADdcc");
        int ans = s1.compareToIgnoreCase(s2);
        System.out.println(ans);
    }
}
